<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>教学管理系统 - 登录</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css">
    <style>
        body {
            background-color: #f0f2f5;
            height: 100vh;
            display: flex;
            align-items: center;
            background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1440 320"><path fill="%231e88e5" fill-opacity="0.2" d="M0,192L48,197.3C96,203,192,213,288,229.3C384,245,480,267,576,250.7C672,235,768,181,864,181.3C960,181,1056,235,1152,234.7C1248,235,1344,181,1392,154.7L1440,128L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z"></path></svg>');
            background-repeat: no-repeat;
            background-position: bottom;
            background-size: 100%;
        }
        .login-container {
            width: 100%;
            max-width: 400px;
            margin: 0 auto;
            padding: 20px;
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        .login-header {
            text-align: center;
            margin-bottom: 30px;
        }
        .login-header h3 {
            color: #1e88e5;
            font-weight: 600;
        }
        .login-logo {
            width: 80px;
            height: 80px;
            margin-bottom: 15px;
        }
        .login-form .form-control {
            height: 45px;
            border-radius: 4px;
        }
        .login-form .input-group-prepend .input-group-text {
            background-color: #e3f2fd;
            color: #1e88e5;
            border-right: none;
        }
        .login-form .form-control:focus {
            border-color: #1e88e5;
            box-shadow: 0 0 0 2px rgba(30, 136, 229, 0.2);
        }
        .login-btn {
            width: 100%;
            height: 45px;
            background-color: #1e88e5;
            border: none;
            border-radius: 4px;
            font-size: 16px;
            font-weight: 500;
            transition: all 0.3s;
        }
        .login-btn:hover {
            background-color: #1976d2;
        }
        .copyright {
            text-align: center;
            margin-top: 30px;
            color: #666;
            font-size: 14px;
        }
        .input-group {
            margin-bottom: 20px;
        }
    </style>
</head>
<body>
<div class="container">
    <div class="login-container">
        <div class="login-header">
            <img src="" class="login-logo" alt="教学管理系统">
            <h3>教学管理系统</h3>
        </div>
        <form id="loginForm" class="login-form" method="post" action="/login">
            <div class="input-group">
                <div class="input-group-prepend">
                    <span class="input-group-text"><i class="fas fa-user"></i></span>
                </div>
                <input type="text" id="username" name="username" class="form-control" placeholder="请输入账号">
            </div>
            <div class="input-group">
                <div class="input-group-prepend">
                    <span class="input-group-text"><i class="fas fa-lock"></i></span>
                </div>
                <input type="password" id="password" name="password" class="form-control" placeholder="请输入密码">
            </div>
            <div class="form-group">
                <button type="submit" class="btn btn-primary login-btn" id="loginBtn">登 录</button>
            </div>
        </form>
        <div class="copyright">
            © 2025 教学管理系统 版权所有
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script src="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css"></script>

<script>
    $(document).ready(function() {
        // 表单提交验证
        $('#loginForm').submit(function(e) {
            e.preventDefault();

            var username = $('#username').val().trim();
            var password = $('#password').val().trim();

            // 验证用户名和密码是否为空
            if (!username) {
                Swal.fire({
                    icon: 'warning',
                    title: '提示',
                    text: '请输入账号',
                    confirmButtonColor: '#1e88e5'
                });
                return false;
            }

            if (!password) {
                Swal.fire({
                    icon: 'warning',
                    title: '提示',
                    text: '请输入密码',
                    confirmButtonColor: '#1e88e5'
                });
                return false;
            }

            // 提交表单
            $.ajax({
                url: '/login',
                type: 'POST',
                data: $(this).serialize(),
                beforeSend: function() {
                    $('#loginBtn').html('<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> 登录中...');
                    $('#loginBtn').prop('disabled', true);
                },
                success: function(response) {
                    if (response.code == 0) {
                        // 登录成功，跳转到首页
                        window.location.href = '/index';
                    } else {
                       // $.modal.msgError("账号或密码错误");
                        // 登录失败，显示错误信息
                        Swal.fire({
                            icon: 'error',
                            title: '登录失败',
                            text: response.msg || '账号或密码错误',
                            confirmButtonColor: '#1e88e5'
                        });
                    }
                },
                error: function() {
                    Swal.fire({
                        icon: 'error',
                        title: '错误',
                        text: '网络请求失败，请稍后再试',
                        confirmButtonColor: '#1e88e5'
                    });
                },
                complete: function() {
                    $('#loginBtn').html('登 录');
                    $('#loginBtn').prop('disabled', false);
                }
            });
        });
    });
</script>
</body>
</html>